import nci60.data.connected.LeadingProtein
import nci60.data.maxquant.Project

////Quering total number of identified proteins
////println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct l.protein.id) from LeadingProtein l where l.protein.description like \'%kinase%\'')[0]
//def kin = 106+12+75+27
//println kin
//def all = kin+33+83+39
//println all
//println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct l.protein.id) from LeadingProtein l where l.protein.description like \'%kinase%\'')[0]
//println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct l.protein.id) from LeadingProtein l where l.protein.description like \'%kinase%\' and l.group.onlyIdentifiedBySite != true and l.group.reverse != true and l.group.contaminant != true')[0]
//println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct l.protein.id) from LeadingProtein l where l.protein.description like \'%kinase%\' and l.group.iBAQ != 0 and l.group.onlyIdentifiedBySite != true and l.group.reverse != true and l.group.contaminant != true')[0]
//println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct l.protein.id) from LeadingProtein l where l.protein.description like \'%kinase%\' and l.group.iBAQ != 0 ')[0]
//println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct l.protein.id) from LeadingProtein l where l.protein.description like \'%kinase%\' and l.group.intensity != 0 ')[0]
//println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct l.protein.id) from LeadingProtein l where l.protein.description like \'%kinase%\' and l.group.iBAQ != 0 and l.group.onlyIdentifiedBySite != true and l.group.reverse != true and l.group.contaminant != true and l.group.intensity != 0 ')[0]
//
////sets the Services in the Upload class, to make them available
//def queryService = ctx.getBean("queryService")
//
//println queryService.getProteinIdsFromQuery('uniprotLike(%kinase%)', null).size()

def genes = []
def file = new File('/media/Tatanka/NCI60/Kinase/genesKinbase2.txt')
file.eachLine(){genes.add(it)}

println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct g.protein.id) from GeneName g where g.name in :names ', [names:genes])[0]

println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct g.protein.id) from GeneName g, LeadingProtein l where g.protein=l.protein and g.name in :names and l.group.iBAQ != 0 and l.group.onlyIdentifiedBySite != true and l.group.reverse != true and l.group.contaminant != true and l.group.intensity != 0', [names:genes])[0]

println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct g.protein.id) from GeneName g, LeadingProtein l where g.protein=l.protein and g.name in :names and l.group.onlyIdentifiedBySite != true and l.group.reverse != true and l.group.contaminant != true', [names:genes])[0]

println 'Identified kinases (total)\t'+ LeadingProtein.executeQuery('select count(distinct g.protein.id) from GeneName g, LeadingProtein l where g.protein=l.protein and g.name in :names and l.group.reverse != true and l.group.contaminant != true and l.group.iBAQ != 0', [names:genes])[0]
//

////Quering total number of identified proteins per experiment (project)
//LeadingProtein.executeQuery('select l.currentProject, count(l.protein.id) from LeadingProtein l group by l.currentProject').each(){line->
//    println 'Identified proteins ('+line[0].name+')\t'+line[1]
//}
//println ''
//
////Data for Venn-Diagramm
////get all experiments (projects) and assigne an alias
//def counter = 1
//def projectIdToAlias = [:]
//println 'Alias\tExperiment'
//Project.findAll().sort(){it.id}.each{
//    println '' + counter + '\t' + it.name
//    projectIdToAlias.put(it.id, counter)
//    counter++
//}
//println ''
//
////get all proteins and corresponding experiments (projects), in which those were identified
//def tempData = [:]      //tempProtein = [protein:[projectIDs]
//LeadingProtein.executeQuery('select l.currentProject, l.protein.id from LeadingProtein l').each(){line->
//    def proj = line[0]
//    def prot = line[1]
//    if(!tempData.containsKey(prot)){tempData.put(prot,[])}
//    tempData[prot].add(projectIdToAlias[proj.id])
//}
//
////form all sets of experiments (projects) and count the identified proteins
//def combinations = [:]  //[set:numberOfIdentifiedProteins]
//tempData.each(){prot, projs->
//    def combinationKey = projs.sort().toString()[1..-2]
//    if(!combinations.containsKey(combinationKey)){combinations.put(combinationKey,0)}
//    combinations[combinationKey]++
//}
//
////print the resulting sets and the number of identified proteins
//println 'Set of experiments\tNumber of identified proteins'
//combinations.sort().each(){key,count->
//    println '' + key + '\t' + count
//}